package com.ph.clouds.tracker.network;


import com.ph.clouds.tracker.Tracker;
import com.ph.clouds.tracker.thread.TrackThreadPoolManager;

import java.util.Map;

/**
 * @Author yushuangjiang
 * @Time 2021/8/3 15:13
 * @Description：
 */
public class TrackHttpEngine {

    private static TrackHttpEngine INSTANCE;

    private TrackHttpEngine() {
    }

    public static TrackHttpEngine getInstance() {
        if (INSTANCE == null) {
            synchronized (Tracker.class) {
                if (INSTANCE == null) {
                    INSTANCE = new TrackHttpEngine();
                }
            }
        }
        return INSTANCE;
    }

    /**
     *
     * @param requestInfo
     * @param header
     * @param url
     * @param dataListener
     */
    public void request(String requestInfo, Map<String,String> header, String url, IDataListener dataListener) {
        IHttpRequest httpRequest = new JsonHttpRequest();
        IHttpListener httpListener = new JsonHttpListener(dataListener);
        TrackThreadPoolManager.getIntance().execute(new HttpTask(requestInfo, header, url, httpRequest, httpListener));
    }
}
